package com.sdp.right.db.sys_menu_button.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdp.right.db.sys_menu_button.mapper.SysMenuButtonMapper;
import com.sdp.right.db.sys_menu_button.service.ISysMenuButtonService;
import com.sdp.right.entity.SysMenuButton;
import com.sdp.right.service.RemoveSystemService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsp
 * @since 2023-10-16
 */
@Service
@DS(value="right")
public class SysMenuButtonServiceImpl extends ServiceImpl<SysMenuButtonMapper, SysMenuButton> implements ISysMenuButtonService,RemoveSystemService{

	@Override
	public List<SysMenuButton> querySysMenuButton(List<String> roleNos,String systemNo) {
		LambdaQueryWrapper<SysMenuButton> queryWrapper = new LambdaQueryWrapper<>();
		for(String roleNo : roleNos) {
			queryWrapper.or(qw->qw.like(SysMenuButton::getQueryRoleNo, "["+roleNo+"]"));
		}
		queryWrapper.eq(SysMenuButton::getSystemNo, systemNo);
		return list(queryWrapper);
	}

	@Override
	public List<SysMenuButton> querySysMenuButton(String roleNo, String systemNo) {
		LambdaQueryWrapper<SysMenuButton> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysMenuButton::getRoleNo, roleNo);
		queryWrapper.eq(SysMenuButton::getSystemNo, systemNo);
		return list(queryWrapper);
	}

	@Override
	public SysMenuButton querySysMenuButton(String btNo) {
		LambdaQueryWrapper<SysMenuButton> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysMenuButton::getBtNo, btNo);
		return getOne(queryWrapper,false);
	}

	@Override
	public List<String> querySysMenuButtonNos(List<String> roleNos, String systemNo) {
		List<String> btNos = new ArrayList<>();
		List<SysMenuButton> list = querySysMenuButton(roleNos, systemNo);
		if(list!=null && list.size()>0) {
			for(SysMenuButton bt : list) {
				btNos.add(bt.getBtNo());
			}
		}
		return btNos;
	}

	@Override
	public void removeBySystemNo(String systemNo) {
		LambdaQueryWrapper<SysMenuButton> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysMenuButton::getSystemNo, systemNo);
		remove(queryWrapper);
		
	}

}
